package org.nox.helloseries.core.connector.tracker.impl;

import org.jdom2.Element;
import org.nox.helloseries.core.connector.tracker.AbstractRSSTorrentSearch;
import org.nox.helloseries.core.util.HelloSeriesConstants;
import org.nox.helloseries.domain.NomTracker;
import org.nox.helloseries.domain.Serie;
import org.nox.helloseries.domain.Version;

public class FrenchTorrentDBSearch extends AbstractRSSTorrentSearch
{
    private final String baseURL = "http://www.frenchtorrentdb.com/rss/000976bf7ac53b869c/tv_";

    @Override
    protected double getTailleFichier( Element e )
    {
        return Double.parseDouble( e.getChild( "enclosure" ).getAttributeValue( "length" ) ) / 1000000;
    }

    @Override
    protected int getSeeds( Element e )
    {
        return HelloSeriesConstants.MAGIC_SEEDS;
    }

    @Override
    protected String getTitre( Element e )
    {
        return e.getChildText( "title" );
    }

    @Override
    protected String getUrl( Element e )
    {
        String url = e.getChild( "enclosure" ).getAttributeValue( "url" ).replace( "&amp;", "&" );
        return url;
    }

    @Override
    protected String getUrlRecherche( Serie serie )
    {
        String url = baseURL;

        // tv_hd_vo n'existe pas
        if ( serie.getQualite().isHd() && serie.getVersion() != Version.VO )
        {
            url += "hd_";
        }

        if ( serie.getVersion().isVF() )
        {
            url += "vf";
        }
        else if ( serie.getVersion().isVOSTFR() )
        {
            url += "vostfr";
        }
        else
        {
            url += "vo";
        }
        return url + ".rss";
    }

    @Override
    protected NomTracker getNomTracker()
    {
        return NomTracker.FRENCHTORRENTDB;
    }

}
